import { useAdminAuthenticationStore } from '../store/adminAuthentication'

const { formData } = useAdminAuthenticationStore()
export const rules = {
  overDate: [{ required: true }],
  appName: [{ required: true }],
  appId: [{ required: true }],
  userId: [{ required: true }],
  domain: [
    { required: true },
    {
      validator: (val: any) => {
        const domainPattern = /^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$/
        const ipPattern = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
        if (formData.type === 0 && !domainPattern.test(val)) {
          return { result: false, message: '域名格式不正确', type: 'error' }
        }
        if (formData.type === 1 && !ipPattern.test(val)) {
          return { result: false, message: 'IP格式不正确', type: 'error' }
        }
        return { result: true }
      }
    }
  ]
}
